#define _CRT_SECURE_NO_WARNINGS 1
class Solution
{
public:
    int squar(int n)
    {
        int sum = 0;
        while (n)
        {
            int bit = n % 10;
            sum += bit * bit;
            n /= 10;
        }
        return sum;
    }
    bool isHappy(int n)
    {
        int slow = n;
        int fast = n;
        do
        {
            slow = squar(slow);
            fast = squar(fast);
            fast = squar(fast);
        } while (slow != fast);
        return slow == 1;

    }
};